﻿/* ******************************************************** */
/* Arcans Project (2010)                                    */
/* Jeu 3D en temps réel par navigateur, conception et       */
/* Développement dans la notice                             */
/* Jeu sous licence GNU GPL v3 (voir NOTICE et COPYING)     */
/* ******************************************************** */

//variables globales ******************************************************************************
var panel = "";
var zone_panel;
//vérification que la page principale est toujours là *********************************************
var scanner = function () {
	if (window.opener == null) { ajaxFun("apanc",1,new Array("1"),""); window.close(); }
	setTimeout("scanner();", 1000);
};
//gestion du onload du pannel, pour récupérer le choix ********************************************
var onloadFun = function (choix) {
	panel = choix;
	zone_panel = document.getElementById("panel");
	bl_panel.ouverture();
	scanner();
};
//gestion générique du panel des messageries ******************************************************
var bl_panel = {
	//création du contexte du panel
	ouverture: function () {
		if (panel == "chat")  bl_chat.ouverture("");
		if (panel == "messages")  bl_meg.ouverture("");
	},
	//réintégration des messageries à la page principale
	reintegrate: function () { window.opener.panel.reintegre(panel); },
	//transition entre chat et message
	transition: function (choix) {
		while (zone_panel.hasChildNodes()) zone_panel.removeChild(zone_panel.firstChild);
		var bt_chat = document.getElementById("bt_chat");
		var bt_message = document.getElementById("bt_message");
		while (bt_chat.hasChildNodes()) bt_chat.removeChild(bt_chat.firstChild);
		while (bt_message.hasChildNodes()) bt_message.removeChild(bt_message.firstChild);
		if (choix == "chat") {
			bt_chat.setAttribute("class", "active");
			bt_chat.appendChild(document.createTextNode("Chat"));
			bt_message.setAttribute("class", "underline");
			var crea_button = document.createElement("button");
			crea_button.setAttribute("onclick", "javascript:bl_panel.transition('messages');");
			crea_button.appendChild(document.createTextNode("Messagerie"));
			bt_message.appendChild(crea_button);
			panel = "chat";
			bl_panel.ouverture();
		}
		else if (choix == "messages") {
			bt_message.setAttribute("class", "active");
			bt_message.appendChild(document.createTextNode("Messagerie"));
			bt_chat.setAttribute("class", "underline");
			var crea_button = document.createElement("button");
			crea_button.setAttribute("onclick", "javascript:bl_panel.transition('chat');");
			crea_button.appendChild(document.createTextNode("Chat"));
			bt_chat.appendChild(crea_button);
			panel = "messages";
			bl_panel.ouverture();
		}
	}
};
//fermeture du panel ******************************************************************************
window.onbeforeunload = function () { bl_panel.reintegrate(); };
//gestion de l'ajax *******************************************************************************
try { var ajax = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e) {
	try { var ajax = new ActiveXObject('Microsoft.XMLHTTP'); }
	catch (e2) { try { var ajax = new XMLHttpRequest(); } catch (e3) { ajax = false; } }
}
var ajaxFun = function (address, nb_param, tab_param, fonction_res) {
	//ajax fonction
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			if (ajax.status == 200) {
				if (fonction_res != "") {
					result = ajax.responseXML;
					infos = result.getElementsByTagName("infos").item(0);
					if (infos.getAttribute("type") == "text") fonction_res(parseInt(infos.getAttribute("value")));
					else if (infos.getAttribute("type") == "xml") fonction_res(result);
				}
			}
		}
	};
	//lancement de l'ajax
	ajax.open( "POST", "?p=" + address,  true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var donnees = "";
	for (var ident = 0; ident < nb_param; ident++) {
		if (ident != 0) donnees = donnees + "&";
		donnees = donnees + "info" + ident + "=" + tab_param[ident];
	}
	ajax.send(donnees);
};